package com.bukkit.feverdream.noon;

import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerListener;

//class
public class NPlayerListener extends PlayerListener {

    private Noon _noon;

    public NPlayerListener(Noon plugin) {
        _noon = plugin;
    }

    @Override
    public void onPlayerCommand(PlayerChatEvent event) {
        Player player = event.getPlayer();
        String hit[] = event.getMessage().replace("  ", " ").split(" ");

        if (hit[0].equalsIgnoreCase("/noon")) {
            if (!_noon.Permissions.Security.permission(player, "noon")) {
                player.sendMessage("Noon: You do not have permission for this action.");
                return;
            }
            if (hit.length > 1) {
                //parse second command word
                if (_noon.setMode(hit[1])) {
                    player.sendMessage("Noon: Mode set to " + hit[1]);
                } else {
                    player.sendMessage("Noon: Invalid mode given. Use /noon <day|sunset|night|sunrise|off>");
                }
            } else {
                player.sendMessage("Noon: No mode given. Use /noon <day|sunset|night|sunrise|off>");
            }
        }
    }
}
